import request from "@/utils/request";


/**
 * 获取货件
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentList(params = {}){
  return request({
    url: `/shipment/getShipmentList`,
    params,
    method: 'get',
  })
}

/**
 * 删除货件
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function delShipment(id){
  return request({
    url: `/shipment/delShipment/${id}`,
    method: 'delete',
  })
}

/**
 * 获取货件详情
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentInfo(id){
  return request({
    url: `/shipment/getShipmentInfo/${id}`,
    method: 'get',
  })
}


/**
 * 确认入库
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function confirmShipment(data){
  return request({
    url: '/shipment/confirmShipment',
    method: 'put',
    data,
    handleError: true,
  })
}

/**
 * 确认送仓
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function deliverShipment(id){
  return request({
    url: `/shipment/deliverShipment/${id}`,
    method: 'put',
    handleError: true,
  })
}

/**
 * 获取某用户的货件情况
 * @param userId
 * @returns {Promise | Promise<unknown>}
 */
export function getUserShipment(userId){
  return request({
    url: `/shipment/getUserShipment/${userId}`,
  })
}

/**
 * 更新某个用户的货件情况
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveUserShipment(data){
  return request({
    url: `/shipment/saveUserShipment`,
    method: 'put',
    data,
  })
}

/**
 * 单独保存箱子数
 * @param data
 * @returns {Promise<unknown>}
 */
export function saveShipmentBox(data){
  return request({
    url: `/shipment/saveShipmentBox`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 保存货件数量
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveShipmentGoods(data){
  return request({
    url: `/shipment/saveShipmentGoods`,
    method: 'put',
    data,
    handleError: true
  })
}

/**
 * 保存多个货件的商品
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveShipmentGoodsList(data){
  return request({
    url: `/shipment/saveShipmentGoodsList`,
    method: 'put',
    data,
    handleError: true
  })
}


/**
 * 获取货件单商品详情
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentGoodsPage(params){
  return request({
    url: '/shipment/getShipmentGoodsPage',
    params,
  })
}


/**
 * 保存箱子数
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveShipmentBoxV2(data){
  return request({
    url: `/shipment/saveShipmentBoxV2`,
    method: 'patch',
    data
  })
}

/**
 * 打印货件单
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentA4PDFById(id){
  return request({
    url: `/shipment/getShipmentA4PDFById/${id}`,
    method: 'get',
    responseType: "arraybuffer",
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 打印入库单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function shipmentPDF(data){
  return request({
    url:`/shipment/shipmentPDF`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000, // 1分钟
    handleError: true,
  })
}

/**
 * 修改货件图片
 * @param data
 * @returns {Promise<unknown>}
 */
export function saveShipmentImg(data){
  return request({
    url: `/shipment/saveShipmentImg`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 获取货件图片
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function getShipmentImgArr(id){
  return request({
    url: `/shipment/getShipmentImgArr/${id}`,
    method: 'get',
  })
}

/**
 * 获取货件里的商品是否有不同步的商品
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function checkShipmentGoodsOrderHidden(id){
  return request({
    url: `/shipment/checkShipmentGoodsOrderHidden/${id}`
  })
}
